//
//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ```` ':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
//
//

import Vue from 'vue';
import iView from 'iview';
import {
    router
} from './router/index';
import {
    appRouter
} from './router/router';
import store from './store';
import App from './app.vue';
import 'iview/dist/styles/iview.css';
// import util from '@/libs/util';
import Events from '@/libs/Events';
import http from '@/libs/http';
import postUrl from '@/libs/postUrl';
import storage from '@/libs/storage';
import Promise from 'es6-promise';

Promise.polyfill();
Vue.use(iView);

Vue.prototype.http = http;
Vue.prototype.events = Events;
Vue.prototype.postUrl = postUrl;
Vue.prototype.storage = storage;
Vue.prototype.errorHandle = (msg) => {
    Vue.prototype.$Notice.error({
        title: '提示',
        desc: msg ? msg : '网络错误，请稍后重试'
    });
};

new Vue({
    el: '#app',
    router: router,
    store: store,
    render: h => h(App),
    data: {
        currentPageName: ''
    },
    mounted() {
        this.currentPageName = this.$route.name;
        // 显示打开的页面的列表
        this.$store.commit('setOpenedList');
        this.$store.commit('initCachepage');
        // 权限菜单过滤相关
        // this.$store.commit('updateMenulist');
        // iview-admin检查更新
        // util.checkUpdate(this);
        //初始化user
    },
    created() {
        this.$store.commit('getUser');
        let tagsList = [];
        appRouter.map((item) => {
            if (item.children.length <= 1) {
                tagsList.push(item.children[0]);
            } else {
                tagsList.push(...item.children);
            }
        });
        this.$store.commit('setTagsList', tagsList);
    }
});
